<script>
import { CommonBusinessForm } from 'jdf-common-biz';
import { getLabel, timeConvert } from 'jdf-util';
import SubResearchIssueFeedbackService from '@/api/domains/subResearchIssueFeedback/SubResearchIssueFeedbackService';
import { messageAlert } from '@/api/utils/pc-message';
import { getBffToken } from '@/api/utils/storage-util';

export default {
  extends: CommonBusinessForm,
  data() {
    return {
      // 后台服务
      service: new SubResearchIssueFeedbackService(),
      // 需要进行主抄送重复校验的字段
      needSendDuplicateCheckFields: [],
      // 自定义校验规则
      baseRules: {},
      formData: {},
      // 表单字段布局配置
      formConfigs: [
        [
          {
            formElName: '带队领导',
            formElCode: 'leadingUserName',
          },
          {
            formElName: '调研开始日期',
            formElCode: 'researchStartDate',
          },
          {
            formElName: '调研结束日期',
            formElCode: 'researchEndDate',
          },
        ],
        [
          {
            formElName: '牵头部门',
            formElCode: 'leadingDepartmentName',
          },
          {
            formElName: '连带规范性动作类型',
            formElCode: 'normativeType',
          },
          {
            formElName: '调研对象',
            formElCode: 'researchUnitName',
          },
        ],
        [
          {
            formElName: '调研主题',
            formElCode: 'researchSubject',
          },
        ],
        [
          {
            formElName: '调研类型',
            formElCode: 'researchType',
          },
          {
            formElName: '调研区县',
            formElCode: 'grassrootsContactName',
          },
          {
            formElName: '乡镇/网络',
            formElCode: 'researchMethod',
          },
        ],
        [
          {
            formElName: '调研层级',
            formElCode: 'researchLevel',
          },
          {
            formElName: '调研形式',
            formElCode: 'researchForm',
          },
        ],
        [
          {
            formElName: '调研组联络人',
            formElCode: 'researchContactName',
          },
          {
            formElName: '被调研单位联络人',
            formElCode: 'conductResearchContactName',
          },
        ],
        [
          {
            formElName: '调研组陪同人员',
            formElCode: 'researchEntourageName',
          },
          {
            formElName: '被调研单位陪同人员',
            formElCode: 'conductResearchEntourageName',
          },
        ],

        [
          {
            formElName: '调研发现问题反馈',
            colSpan: 24,
            subTitle: true,
          },
        ],
        [
          {
            formElCode: 'problemTitle',
            formElName: '问题标题',
          },
        ],
        [
          {
            formElCode: 'problemDescribe',
            formElName: '问题描述',
          },
        ],
        [
          {
            formElCode: 'departmentName',
            formElName: '主办部门',
          },
        ],
        [
          {
            formElCode: 'departmentFeedback',
            formElName: '主办部门反馈',
            attrs: {
              type: 'textarea',
            },
          },
        ],
        [
          {
            formElCode: 'file',
            formElName: '反馈附件',
            elType: 'uploadFile',
            attrs: {
              bizId: () => this.piid,
              headers: {
                Authorization: getBffToken(),
              },
              spaceCode: 'default',
            },
          },
        ],
      ],
      // 主抄送是否获取网关数据, false为不获取，true为获取
      isGateWayData: false,
      // 采用ucfg的数据字典，不采用数据库表中字典值
      isSelfDict: false,
      // 需新增弹窗提示的环节
      needPopupTips: ['draft', 'departmentDeputyHandle', 'divisionLeaderHandle', 'departmentPersonnelHandle'],
    };
  },
  watch: {
    'formData.title': {
      handler(val) {
        this.$emit('update:processTitle', val);
      },
    },
  },
  methods: {
    /**
     * 表单数据初始化后调用的方法
     * */
    afterInit(formData) {
      this.$emit('update:documentFormTitle', '调研发现问题反馈子流程');
      if (this.needPopupTips.includes(this.nodeId) && !this.isDone) {
        messageAlert('请在七个工作日内办复。');
      }
    },
    /**
     * 保存业务数据前调用的方法
     */
    beforeSaveBusinessForm() {
      const { formData } = this;
      this.bizSet({
        problem: {
          ...formData.problem,
          departmentFeedback: formData.departmentFeedback,
        },
      });
    },
  },
};
</script>

<style scoped lang="scss">
::v-deep .btn-order .el-button {
  position: absolute;
}
</style>
